const _ = require('lodash');

module.exports = {
  schedule: {
    cron: '30 0,20,40 6-23 * * ?',
    type: 'worker',
    env: ['pachong'],
    // immediate: true
  },

  async task(ctx) {

    const r1 = await ctx.service.crawlerSvc.juejinAll();
    const r2 = await ctx.service.crawlerSvc.longtengwang();

    const topics = r1.concat(r2);

    const shuffle_topics = _.shuffle(topics);

    const result = await ctx.service.topicSvc.importTopics(shuffle_topics);
    ctx.logger.info(`juejin ready ${topics.length} success ${result}`);
  }
};
